package day05;

public class Object03 {                     //改进：用一个count变量记录数组中元素的个数，每当增删时更新
    public static void main(String[] args) {
        StuBean[] student = new StuBean[3];
        StuBean stu1= new StuBean("heima002",18,"xiaoming");
        student[0] = stu1;
        StuBean stu2= new StuBean("heima002",19,"xiaomei");
        boolean flag = true;
        for (int i = 0; i < student.length;i++ ) {
            if(stu2.getNum().equals(student[i].getNum())){
                System.out.println("非法!");
                flag = false;
                break;
            }
        }
        if(flag){
            student[1] = stu2;
        }

        for (int i = 0; i < student.length; i++) {
            if(student[i]!=null) student[i].getInf();
        }

        for (int i = 0; i < student.length; i++) {
            if(student[i]!=null){
                if(student[i].getNum().equals("heima003")){
                student[i]=null;
                }
            else System.out.println("未查到");
            }
        }

        for (int i = 0; i < student.length; i++) {
            if(student[i]!=null) student[i].getInf();
        }

        for (int i = 0; i < student.length; i++) {
            if(student[i]!=null) {
                if(student[i].getNum().equals("heima002")){
                student[i].setAge(student[i].getAge()+1);
                }
            }
        }
    }

}
